<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>深拷贝</title>
</head>
<body>
    <script>
        // 目标数据
        const school = {
            test:null,
            age:18,
            name:'atguigu',
            boss:{
                name:'刚哥',
                age:46
            },
            positions:['北京','上海','西安','深圳','武汉'],
            teach:function(){
                console.log('coding！');
            }
        }
        

        // 1. 创建一个容器对象
        let result = {};
        result['test'] = null;
        // 2. 拷贝name属性及属性值
        result['name'] = school['name'];
        // 拷贝position 数组
           // 1. 创建 position容器空数组
        result['positions'] = [];
        // 2. 将数组中的数据 拷贝
        result['positions'][0] = school['positions'][0];
        result['positions'][1] = school['positions'][1];
        result['positions'][2] = school['positions'][2];
        result['positions'][3] = school['positions'][3];
        result['positions'][4] = school['positions'][4];

        // 创建boss 空对象
        result['boss'] = {};
        result['boss']['name'] = school['boss']['name'];
        result['boss']['age'] = school['boss']['age'];
        
        // 拷贝方法
        result['teach'] = school['teach'];

        result.boss.name = '刚哥123123';
        result.positions[0] = 'beijing';

        console.log('result',result);
        console.log('school',school);





    </script>
</body>
</html>